package com.asap.demo.utils;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.stream.Stream;

/**
 * 读文件内容的操作
 */
public class FileReader {
    private static final Logger logger = LoggerFactory.getLogger(FileReader.class);

    /**
     * NIO方式读取文件内容
     * @param fileName
     * @return
     * @throws Exception
     */
    public String readFileNIO(String fileName) throws Exception {
        StringBuffer stringBuffer = new StringBuffer();
        try (Stream<String> fileLines = Files.lines(Paths.get(fileName))) {
            fileLines.forEach(line -> {
                stringBuffer.append(line.trim()).append("\n");
            });
        } catch (Exception e) {
            logger.error("",e,"");
        }
        return stringBuffer.toString();
    }
}
